#include "touchbutton.h"
#include "qdebug.h"

#include <QEvent>
#include <QTouchEvent>

TouchButton::TouchButton(QWidget *parent):QPushButton(parent) {
    setAttribute(Qt::WA_AcceptTouchEvents,true);
}

TouchButton::TouchButton(const QString &text, QWidget *parent):QPushButton(text,parent)
{
    setAttribute(Qt::WA_AcceptTouchEvents,true);
}

TouchButton::TouchButton(const QIcon &icon, const QString &text, QWidget *parent):QPushButton(icon,text,parent)
{
    setAttribute(Qt::WA_AcceptTouchEvents,true);
}

bool TouchButton::event(QEvent *event)
{
    if (event->type() == QEvent::TouchBegin ) {
        this->setDown(true);
        emit pressed();
        return true;
    }
    else if(event->type() == QEvent::TouchEnd)
    {
        this->setDown(false);
        emit released();
        return true;
    }

    return QPushButton::event(event);
}
